#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>

typedef int BTDataType;
typedef struct BTreeNode
{
	BTDataType val;
	struct BTreeNode* left;
	struct BTreeNode* right;
}BTNode;

BTNode* BuyNode(BTDataType x)
{
	BTNode* node = (BTNode*)malloc(sizeof(BTNode));
	if (node == NULL)
	{
		perror("malloc fail");
		exit(1);
	}
	node->val = x;
	node->left = node->right = NULL;
	return node;
}
BTNode* BTCreat()
{
	BTNode* n1 = BuyNode(1);
	BTNode* n2 = BuyNode(2);
	BTNode* n3 = BuyNode(3);
	BTNode* n4 = BuyNode(4);
	BTNode* n5 = BuyNode(5);
	BTNode* n6 = BuyNode(6);
	n1->left = n2;
	n1->right = n4;
	n2->left = n3;
	n4->left = n5;
	n4->right = n6;
	return n1;
}
void PrevOrder(BTNode* root)
{
	if (root == NULL)
	{
		printf("N ");
		return;
	}
	printf("%d ", root->val);
	PrevOrder(root->left);
	PrevOrder(root->right);
}

void InOrder(BTNode* root)
{
	if (root == NULL)
	{
		printf("N ");
		return;
	}
	InOrder(root->left);
	printf("%d ", root->val);
	InOrder(root->right);
}
void AfterOrder(BTNode* root)
{
	if (root == NULL)
	{
		printf("N ");
		return;
	}
	AfterOrder(root->left);
	AfterOrder(root->right);
	printf("%d ", root->val);
}
int TreeSize(BTNode* root)
{
	if (root == NULL)
	{
		return 0;
	}
	return 1 + TreeSize(root->left) + TreeSize(root->right);
}
int TreeLeftSize(BTNode* root)
{
	if (root == NULL)
	{
		return 0;
	}
	if (root->left == NULL && root->right == NULL)
	{
		return 1;
	}
	return TreeLeftSize(root->left) + TreeLeftSize(root->right);
}
int TreeDepth(BTNode* root)
{
	if (root == NULL)
	{
		return 0;
	}
	int left = 0;
	int right = 0;
	left = TreeDepth(root->left);
	right = TreeDepth(root->right);
	return left > right ? left + 1 : right + 1;
}
int main()
{
	BTNode* root = BTCreat();
	//PrevOrder(root);
	//InOrder(root);
	//AfterOrder(root);
	//printf("%d ", TreeSize(root));
	//printf("%d ", TreeLeftSize(root));
	printf("%d ", TreeDepth(root));
	return 0;
}